package main 

import "fmt"
import "ch03/classpath"
import (
	"ch03/classfile"
	"ch04/rtda"
)

func main() {
	cmd:=parseCmd()
	if cmd.versionFlag {
		fmt.Println("version 0.0.1")
	}else if cmd.helpFlag || cmd.class ==""{
		printUsage()
	}else{
		startJVM(cmd)
	}
}

func startJVM(cmd *Cmd){
	frame := rtda.NewFrame(100, 100)
	testLocalVars(frame.LocalVars())


}
func testLocalVars(vars rtda.LocalVars) {
	vars.SetInt(0,100)
	vars.SetInt(1,-100)
	vars.SetLong(2,2997924580)
	vars.SetLong(4,2-997924580)
	vars.SetFloat(6,3.1)
	vars.SetDouble(7,2.7)
	vars.SetRef(9,nil)
	println(vars.GetInt(0))
}
func printClassInfo(cf *classfile.ClassFile) {
	fmt.Printf("version: %v,%v\n", cf.MajorVersion(),cf.MinorVersion())
	fmt.Printf("constants count: %v\n", len(cf.ConstantPool()))
	fmt.Printf("access flags: 0X %x\n",cf.AccessFlags())
	fmt.Printf("this class: %v\n", cf.ClassName())
	fmt.Printf("super class class: %v\n", cf.SuperClassName())
	fmt.Printf("interfaces: %v\n", cf.InterfaceNames())
	fmt.Printf("fields count: %v\n", len(cf.Fields()))
	for _,f:=range cf.Fields() {
		fmt.Printf(" %s\n", f.Name())
	}
	fmt.Printf("methods count: %v\n", len(cf.Methods()))
	for _,m:=range cf.Methods() {
		fmt.Printf(" %s\n", m.Name())
	}

}
func loadClass(className string, cp *classpath.Classpath) *classfile.ClassFile {
	classData,_,err:=cp.ReadClass(className)
	if err != nil {
		panic(err)
	}
	println(classData)
	cf,err :=classfile.Parse(classData)
	if err != nil {
		panic(err)
	}
	return cf
}